package com.oocl.scan.store;

import com.oocl.scan.model.JavaClassElement;
import java.util.concurrent.ConcurrentLinkedQueue;

public class JavaClassStore implements Store<JavaClassElement> {

  private ConcurrentLinkedQueue<JavaClassElement> javaClassElementQueue;

  private static JavaClassStore javaClassStore;

  private JavaClassStore() {
    javaClassElementQueue = new ConcurrentLinkedQueue<>();
  }

  public static JavaClassStore getInstance() {
    if (javaClassStore == null) {
      synchronized (JavaClassStore.class) {
        if (javaClassStore == null) {
          javaClassStore = new JavaClassStore();
        }
      }
    }
    return javaClassStore;
  }

  public void add(JavaClassElement javaClassElement) {
    javaClassElementQueue.add(javaClassElement);
  }

  public JavaClassElement poll() {
    return javaClassElementQueue.poll();
  }

  public int getCount() {
    return this.javaClassElementQueue.size();
  }

  public Object[] getQueue(){
    return javaClassElementQueue.toArray();
  }
}
